package com.example.demo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.Arrays;
import java.util.List;

@RequestMapping("/request")
@RestController
public class RequestController {

    @RequestMapping("/hello")
    public String hello(){
        return "hello,Spring boot";
    }

    @RequestMapping("r1")
    public String r1(String name){
        return name;
    }

    @RequestMapping("r2")
    public String r2(Integer age){
        return ""+age;
    }

    @RequestMapping("/r3")
    public String r3(int age){
        return "接到参数, age:"+age;
    }

    @RequestMapping("r4")
    public String r4(Integer age,String name){
        return age+" "+name;
    }

    @RequestMapping("/r5")
    public String r5(Student student){
        return student+"";
    }

    @RequestMapping("r6")
    public String r6(@RequestParam(value="name",required = false) String usrName){
        return usrName;
    }

    @RequestMapping("/r7")
    public String r7(String[] array){
        return "Array:"+ Arrays.toString(array);
    }

    //传递 list 需要 加 @RequestParam
    @RequestMapping("/r8")
    public String r8(@RequestParam(required = false) List<String> list){
        return "List:"+list;
    }

    //获取json
    //普通字符串不需要加注解
    @RequestMapping("/r9")
    public String r9(@RequestBody Student student){
        return "接到参数, student:"+student;
    }
    //从路径中获取参数
    @RequestMapping("/r10/{articleId}")
    public String r10(@PathVariable("articleId") Integer articleId ){
        return ""+articleId;
    }

    //上传文件 part
    @RequestMapping("/r11")
    public String r11(MultipartFile imgFile){
        String originalFilename = imgFile.getOriginalFilename();
        return " "+originalFilename;
    }

}







